package com.quanyue.music.system.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.quanyue.music.domain.constant.UserRole;
import com.quanyue.music.domain.entity.HotStyle;
import com.quanyue.music.system.mapper.HotStyleMapper;
import com.quanyue.music.system.service.HotStyleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "峰值规则设置")
@Scope(role = UserRole.MANAGER)
@RestController
@RequestMapping("/api")
public class HotStyleController {
    @Autowired
    private HotStyleService hotStyleService;
    @Autowired
    private HotStyleMapper hotStyleMapper;

    @ApiOperation(value = "添加规则")
    @PostMapping(value = "/hot/style/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> add(@RequestBody HotStyle hotStyle) {
        hotStyleService.add(hotStyle);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "修改规则")
    @PostMapping(value = "/hot/style/update", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> update(@RequestBody HotStyle hotStyle) {
        hotStyleService.update(hotStyle);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "删除规则")
    @DeleteMapping(value = "/hot/style/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> delete(@RequestParam("id") String id) {
        hotStyleService.delete(id);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "查询规则")
    @GetMapping(value = "/hot/style/find", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<List<HotStyle>> findList() {
        return ServiceResult.success(hotStyleMapper.findAllValid());
    }
}
